<template>
   <PanelSplitTwo bottomToolbarHeight="0" :num="2" :sizes="20">
    <template #top>
      <SetUserSelect
        :key="keys"
        class="queryForm"
        :formData="orderSelect"
        v-model:queryParams="paginationParams"
        @selectFunc="selectFunc"
      ></SetUserSelect>
    </template>
     <template #centerToolbar>
        <div class="vex_flex">
          <el-row :gutter="20" style="margin-bottom: 10px">
            <!-- <el-col :span="1.5">
              <el-button @click="handleQuery(0)">新增</el-button>
            </el-col> -->
            <el-col :span="1.5">
              <el-button :disabled="selectedList.length !=1" @click="handleQuery(1)">查看</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button :disabled="selectedList.length !=1" @click="cliCAuditFun">同意</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button :disabled="selectedList.length !=1" @click="cliRefuseFun">驳回</el-button>
            </el-col>
            <el-col :span="1.5">
              <el-button @click="handleExport">导出</el-button>
            </el-col>
            <!-- <el-col :span="1.5">
              <el-button @click="handleQuery">取消</el-button>
            </el-col> -->
          </el-row>
        <VxeTableGrid
          :key="keys"
          style="flex: 1;"
          :tableColumn="tableColumn"
          :tableLoading="tableLoading"
          :dataList="dataList"
          :showPagination="true"
          :paginationParams="paginationParams"
          @getList="setQueryParams"
          @selectedChange="selectedChange"
        >
        </VxeTableGrid>
        <cliRefuseDom ref="cliRefuseRef" :id="Id" url="/task/apply/refuse" @updateData="updateData"></cliRefuseDom>
      </div>
     </template>
   </PanelSplitTwo>
</template>

<script setup lang="jsx">
import { useRouter } from 'vue-router'
import { forceLogout, list as initData } from "@/api/monitor/online";
import { getprovince } from "@/api/basicManagement/hospital";
import { agencyList  } from "@/api/basicManagement/agencyMana";

import { drugList  } from "@/api/basicManagement/varietyMana";
import { applyList, delapply, cliCAudit, cliRefuse  } from "@/api/missionPlan";
import { watch, getCurrentInstance, ref } from "vue";
import datas from './data.js'
let keys = ref(0);
const { paginationParams, orderSelect }  = datas
const { proxy } = getCurrentInstance();
const router= useRouter ()
const dialogVisible = ref(false)
const handleClose = () => {
  dialogVisible.value = false
}
const { timed_task_type, mission_plan_status } = proxy.useDict("timed_task_type", "mission_plan_status");




const dataLists = ref([])
const tableColumn = ref([
  { type: "checkbox", width: 60, fixed: null },
  { field: "name", title: "任务名称" },
  { field: "type", title: "类型",
  slots: { default: ({ row }, h) => {
    return [<dict-tag options={ timed_task_type.value } value={ row.type }></dict-tag>]
  }} },
  { field: "mrName", title: "代表" },
  { field: "agencyName", title: "代理商" },
  { field: "province", title: "省份"},
  { field: "drugName", title: "品种" },
  { field: "applyQty", title: "申请数量"},
  { field: "hospital", title: "医院"},
  { field: "startTime", title: "开始时间"},
  { field: "endTime", title: "截止时间"},
  { field: "status", title: "状态",
  slots: { default: ({ row }, h) => {
    return [<dict-tag options={ mission_plan_status.value } value={ row.status }></dict-tag>]
  }} },
])
const onlineList = ref([]);
const total = ref(0);
const pageNum = ref(1);
const pageSize = ref(10);
let tableLoading = ref(false)
const dataList = ref([
])

const queryParams = ref({
  ipaddr: undefined,
  userName: undefined
});
// 切换分页
  function setQueryParams(val) {
    console.log(val)
    paginationParams.pageNum = val.pageNum;
    paginationParams.pageSize = val.pageSize;
    hospitalLists()
  }
  let Id = ref('')
  // 选择表格
  let selectedList = ref([])
  let status = ref(null)
  let executedQty = ref()
  function selectedChange(val) {
    Id.value = val.currentItem.id
    executedQty.value = val.currentItem.executedQty
    status.value = val.currentItem.status
    selectedList.value = val.selectedList
  }
/** 新增|修改 */
function handleQuery(type) {
  router.push({
    path: '/missionPlan/chekMissionPlan',
    query: {
      id: type == 1? Id.value : undefined,
      type: type == 1? undefined : 'add'
    }
  })
}

const hospitalLists = () => {
  // platformNum
  applyList({
    ...paginationParams.value,
  }).then((res) => {
    paginationParams.value.total = res.total
    dataList.value = res.rows
  })
}
hospitalLists()
const selectFunc = () => {
  paginationParams.value.pageNum = 1
  hospitalLists()
}
const cliCAuditFun = () => {
  if (status.value == 0) {
    cliCAudit({
      id: Id.value
    }).then(() => {
      proxy.$modal.msgSuccess('已同意')
      hospitalLists()
      keys.value = new Date().getTime()
      selectedList.value = []
    })
  } else {
    proxy.$modal.msgWarning('已申请的任务才能同意')
  }
  
}
const cliRefuseFun = () => {
  if (!executedQty.value) {
    proxy.$refs['cliRefuseRef'].show()
    keys.value = new Date().getTime()
    selectedList.value = []
  } else {
    proxy.$modal.msgWarning('进行中的任务不能驳回')
  }
  
}
const updateData = () => {
  hospitalLists()
}
const handleExport = () => {
  proxy.download("/task/apply/export", {
    ...paginationParams.value
  }, `config_${new Date().getTime()}.xlsx`);
}
</script>
<style scoped>
  .app-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 85px);
    overflow: hidden;
  }
  .vex_flex {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
  }
  .flexmin {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
</style>